#ifndef _BDB_H
#define _BDB_H
#include "fclude.h"
#include "db.h"
#include "directoryDB.h"
/* Directory For DataBase*/


typedef struct {

	DB_ENV *dbenv; /* Hold the envieroment var*/ 
	const char *data_dir;
	DB * extention;
	DB * name2ext; /* secondary db for extention->name*/
	DB * users;
	DB * dialplan;	
}dbs_t;

/*  Every Body use this global var */
extern dbs_t dbs;

typedef struct switch_dbs {
    DB_ENV *dbenv;  
    const char *data_dir;
    const char 	*home;	
    DB *directory_dbp; /* Database containing inventory information */
    DB *dialplan_dbp;    /* Database containing vendor information */
    DB *users_sdbp; /* Index based on the extention user name  index */

    char *db_home_dir;             /* Directory containing the database files */
    char *directory_db_name;  /* directory  database */
    char *users_db_name;     /* users secondary database*/			
    char *dialplan_db_name; /* Name of the dialplane  database */
    char *configuration_db_name;    /* Name of the configuration database */
} SWITCH_DBS;

typedef struct user {
    char name[MAXFIELD];             /* Vendor name */
    char street[MAXFIELD];           /* Street name and number */
    char city[MAXFIELD];             /* City */
    char state[3];                   /* Two-digit US state code */
    char zipcode[6];                 /* US zipcode */
    char phone_number[13];           /* Vendor phone number */
    char note[MAXLINE];	
} USER;
/* Function prototypes 
 *	open /close database , openflaqgs must be DB_CREATE or DB_RDONLY
 * */
int  database_open(int flag);
int  database_close();

size_t
pack_string(char *buffer, char *string, size_t start_pos);

/* create DBT for some simple DATATYPES */
DBT mk_empty_dbt();

DBT mk_uint_dbt(unsigned int *i);
DBT mk_string_dbt(const char * str);

/* Comparison Function for unsigned int keys*/
int compare_uint(DB *dbp ,const DBT *a,const DBT * b, size_t *lockp );
int compare_string(DB *dbp ,const DBT *a,const DBT * b, size_t *lockp );




/*
 Replace '<' and  '>'  by  '[' ']' in the string 
 replace '\n'  by ' ' if rem_nl!=0 

 * */
#define REMOVE_NL 0
#define KEEP_NL 1

void remove_html(char * str ,int rem_nl);

/* Standard action arguments: user name, user level, arguments
 *    Number of arguments is kept in actions structure (eventdb.c)*/
typedef int(dbsecondary_func)(DB *secdb, const DBT *pkey, const DBT *pdata, DBT *skey);
 

extern dbsecondary_func   db_name_extentionid ;



#endif
